package com.mail.dubbo.api;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.mail.dubbo.mapper.SmsHomeBrandMapper;
import com.mail.model.db.SmsHomeBrand;
import org.apache.commons.lang.StringUtils;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

@DubboService
public class SmsHomeBrandApiImpl implements SmsHomeBrandApi {

    @Autowired
    private SmsHomeBrandMapper smsHomeBrandMapper;

    @Override
    public void save(SmsHomeBrand homeBrand) {
        smsHomeBrandMapper.insert(homeBrand);
    }

    @Override
    public void deleteBrand(List<Long> ids) {
        smsHomeBrandMapper.deleteBatchIds(ids);
    }

    @Override
    public Page<SmsHomeBrand> getBrandByPage(Long pageNum, Long pageSize, String brandName, Integer recommendStatus) {
        Page<SmsHomeBrand> page = new Page<>(pageNum, pageSize);
        LambdaQueryWrapper<SmsHomeBrand> wrapper = new LambdaQueryWrapper<>();
        wrapper.like(StringUtils.isNotEmpty(brandName), SmsHomeBrand::getBrandName, brandName)
                .eq(recommendStatus != null, SmsHomeBrand::getRecommendStatus, recommendStatus);
        Page<SmsHomeBrand> page1 = smsHomeBrandMapper.selectPage(page, wrapper);
        return page1;
    }

    @Override
    public void updateBrand(Long id, Integer recommendStatus) {
        SmsHomeBrand homeBrand = new SmsHomeBrand();
        homeBrand.setId(id);
        homeBrand.setRecommendStatus(recommendStatus);
        smsHomeBrandMapper.updateById(homeBrand);

    }

    @Override
    public void updateSortBrand(Long id, Integer sort) {
        SmsHomeBrand homeBrand = new SmsHomeBrand();
        homeBrand.setId(id);
        homeBrand.setSort(sort);
        smsHomeBrandMapper.updateById(homeBrand);
    }


}
